package com.txunda.zhuohired.adapter.user.my;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.user.my.PriceDetailBean;

import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/8 14:04
 * 功能描述：账户明细adapter
 * 联系方式：jiahuanchen@126.com
 */

public class PriceDetailAdapter extends BaseAdapter {
    private Context context;
    private ViewHolder holder;
    private List<PriceDetailBean.DataBean> priceDetailList;

    public PriceDetailAdapter(Context context, List<PriceDetailBean.DataBean> priceDetailList) {
        this.context = context;
        this.priceDetailList = priceDetailList;
    }

    @Override
    public int getCount() {
        return priceDetailList.size();
    }

    @Override
    public Object getItem(int i) {
        return priceDetailList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_price_detail, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (TextUtils.isEmpty(priceDetailList.get(i).getTitle())) {
            holder.tv_item_price_detail_tittle.setVisibility(View.GONE);
        } else {
            holder.tv_item_price_detail_tittle.setVisibility(View.VISIBLE);
            holder.tv_item_price_detail_tittle.setText(priceDetailList.get(i).getTitle());
        }
        if (TextUtils.isEmpty(priceDetailList.get(i).getCreate_time())) {
            holder.tv_item_price_detail_time.setVisibility(View.GONE);
        } else {
            holder.tv_item_price_detail_time.setVisibility(View.VISIBLE);
            holder.tv_item_price_detail_time.setText(priceDetailList.get(i).getCreate_time());
        }

        if (TextUtils.isEmpty(priceDetailList.get(i).getMoney())) {
            holder.tv_item_price_detail_price.setVisibility(View.GONE);
        } else {
            holder.tv_item_price_detail_price.setVisibility(View.VISIBLE);
            if ("1".equals(priceDetailList.get(i).getType())) {
                holder.tv_item_price_detail_price.setText("+" + priceDetailList.get(i).getMoney());
            } else {
                holder.tv_item_price_detail_price.setText("-" + priceDetailList.get(i).getMoney());
            }
        }
        return view;
    }

    class ViewHolder {
        /**
         * 标题
         */
        @ViewInject(R.id.tv_item_price_detail_tittle)
        private TextView tv_item_price_detail_tittle;
        /**
         * 时间
         */
        @ViewInject(R.id.tv_item_price_detail_time)
        private TextView tv_item_price_detail_time;
        /**
         * 钱数
         */
        @ViewInject(R.id.tv_item_price_detail_price)
        private TextView tv_item_price_detail_price;
    }
}
